#use strict;
use warnings;

use Win32::OleAccxs;

use Data::Dumper;


my $wnd = AccessibleObjectFromWindow;
#my $wnd = AccessibleObjectFromPoint(600, 600);
print Dumper($wnd);
#Win32::OleAccxs::ChildCount($wnd);

#print $wnd->ChildCount();


sub GoThrough($$) {
    my $acc = shift;
    my $deep = shift;

    return unless (!$acc ||  ref($acc));

    my $cnt = $acc->ChildCount();

    my @loc = $acc->Location();
    my @stats = $acc->GetStateText();
    #print "@stats\n";
    print ' 'x$deep, $cnt, ",", $acc->Name, ",(@loc),[@stats],", 
        $acc->GetRoleText(), ",", $acc->Value(), ",", $acc->Description, ",", $acc->GetWindowHwnd,   "\n";

    if ($cnt > 0) {

        my @children = $acc->Children();
        #print "Child count: ", scalar @children, "\n";
        #print Dumper(@children);
        
        for my $child (@children) {

            if ($child->{id} == 0) {
                GoThrough($child, $deep+1);
            }
            else {
                $deep ++;
                @loc = $child->Location;
                @stats = $child->GetStateText;
                #print "@stats\n";
                print ' 'x$deep, 0, ",", $child->Name(), ",(@loc),[@stats],",
                    $child->GetRoleText(), ",", $child->Value(), ",", $acc->Description, ",", $child->GetWindowHwnd, "\n";
                $deep --;
            }

            #$deep ++;
            #@loc = $child->Location;
            #print ' 'x$deep, $child->ChildCount(), ",", $child->Name(), ",", "(@loc)", ",", 
            #    $child->State(), ",", $child->Role(), ",", $child->Value(), "\n";
            #$deep --;
        }
    }
}

GoThrough($wnd, 0);
